<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id = 'btn'>新歌速递</button>
    <ul id="ul">
        
    </ul>
    <script>
        const btn = document.getElementById('btn')
        btn.addEventListener('click',()=>{
            //朝网易云的服务器上的后端代码发一个http请求
            let xhr = new XMLHttpRequest();
            xhr.open('GET','http://u.ronki.moe:3000/top/song?type=7',true)
            xhr.onreadystatechange = () =>{
                if(xhr.readyState ===4 && xhr.status ===200){
                    
                    let res = JSON.parse(xhr.responseText)
                    console.log(res);
                    res.data.forEach((song) =>{
                        let li = document.createElement('li')
                        li.innerHTML = song.name
                        document.getElementById('ul').appendChild(li)
                    })
                }
            }
            xhr.send();
        })
    </script>
</body>
</html>